<template>
  <div class="page-bg">
    <div class="logo-container">
      <img src="@/assets/img/login/logo.png" alt="Logo" class="logo" />
    </div>
    <div class="text-container">
      <h1 class="title">数字化投资系统</h1>
    </div>

    <div class="login-container">
      <div class="left-image">
        <img src="@/assets/img/login/1.png" alt="Left Image" />
      </div>

      <div class="login-box">
        <div class="login-title-container">
          <h2 class="login-title">重置密码</h2>
        </div>

        <el-form ref="resetFormRef" :model="resetForm" :rules="resetRules" size="large" style="margin-top: 30px">
          <el-form-item prop="username">
            <el-input v-model="resetForm.username" placeholder="请输入用户名" clearable />
          </el-form-item>

          <el-form-item prop="phone">
            <el-input v-model="resetForm.phone" placeholder="请输入手机号" clearable />
          </el-form-item>

          <el-form-item prop="email">
            <el-input v-model="resetForm.email" placeholder="请输入邮箱" clearable />
          </el-form-item>

          <el-button type="primary" class="w-full" :loading="resetLoading" @click="handleReset">
            确认重置
          </el-button>
        </el-form>
      </div>

      <div class="copyright">
        <h1>版权所有：©山西汾飞信息技术有限公司,山西综改示范区太原唐槐路77号山西智创城1号基地4号楼6层641-642室</h1>
        <h1>备案号:晋ICP备10018730号-1</h1>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import axios from 'axios'

const resetFormRef = ref<FormInstance>()
const resetLoading = ref(false)

const resetForm = reactive({
  username: '',
  phone: '',
  email: ''
})

const resetRules: FormRules = {
  username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  phone: [
    { required: true, message: '请输入手机号', trigger: 'blur' },
    { pattern: /^1[3-9]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' }
  ],
  email: [
    { required: true, message: '请输入邮箱', trigger: 'blur' },
    { type: 'email', message: '邮箱格式不正确', trigger: 'blur' }
  ]
}

async function handleReset() {
  try {
    await resetFormRef.value!.validate()
    resetLoading.value = true

    await axios.post('/api/reset-password', resetForm) // 换成真实地址
    ElMessage.success('重置成功，请注意查收短信/邮件')
    resetFormRef.value!.resetFields()
  } catch (e: any) {
    ElMessage.error(e?.response?.data?.msg || '请求失败')
  } finally {
    resetLoading.value = false
  }
}
</script>


<style scoped>
.tabs {
  margin-bottom: 20px;
}

:deep(.el-tabs__nav-wrap::after) {
  display: none;
}

:deep(.el-tabs__item) {
  font-size: 20px;
  color: #98A4BF;
  padding: 0 20px 8px 0;
  border: none;
}

:deep(.el-tabs__item.is-active) {
  color: #333;
  font-weight: 600;
}

.page-bg {
  min-height: 100vh;
  background-image: url('@/assets/img/login/bg.png') !important;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.logo-container {
  position: absolute;
  top: 75px;
  left: 81px;
  z-index: 10;
}

.logo {
  width: 51px;
  height: 53px;
  padding: 2px;
}

.text-container {
  position: absolute;
  top: 83px;
  left: 162px;
  z-index: 10;
}

.title {
  font-size: 32px;
  color: #006DB8;
  font-family: Arial;
  font-weight: bold;
  line-height: 38px;
}

.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1002px;
  height: auto;
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 5px 5px 5px 0 rgba(0, 0, 0, 0, 0.3);
  padding: 79px 0;
}

.left-image {
  width: 374px;
  height: 352px;
  float: left;
  padding: 2px;
  margin-left: 20px;
  margin-left: 20px;
  margin-top: 20px;
}

.login-box {
  width: 350px;
  height: auto;
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 5px 5px 5px 0 rgba(0, 0, 0, 0, 0.3);
  padding: 40px;
}

.login-title-container {
  margin-bottom: 20px;
}

.login-title {
  font-size: 28px;
  color: #333;
  font-family: Arial;
  text-align: left;
  margin: 0;
  padding: 2px;
}

.tabs {
  display: flex;
  justify-content: left;
  margin-bottom: 20px;
  position: relative;
  z-index: 1;
}

.tab-button {
  top: 382px;
  left: 1002px;
  color: #98A4BF;
  font-size: 20px;
  background-color: #fff;
  padding: 0;
  border: 0;
  margin-right: 39px;
  cursor: pointer;
}


.tab-button.active {
  color: #333;
}

.captcha-container {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.captcha-image {
  width: 96px;
  height: 50px;
}

.refresh-icon {
  width: 25px;
  height: 25px;
  cursor: pointer;
}

.icon {
  width: 35px;
  height: 35px;
  margin: 0 10px;
}

.el-input__inner {
  padding: 5px 10px;
  font-size: 14px;
}

.el-button {
  width: 100%;
  padding: 10px;
  font-size: 16px;
  border-radius: 4px;
}


.text-sm {
  font-size: 14px;

}

.text-blue-600 {
  color: #409EFF;
}

.login-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.forgot-password {
  color: #006DB8;
  text-decoration: none;
  font-size: 16px;
}

.forgot-password:hover {
  text-decoration: underline;
}

:deep(.el-checkbox__inner) {
  width: 16px;
  height: 16px;
  border: 2px solid #dcdfe6;
}

:deep(.el-checkbox__inner::after) {
  height: 8px;
  width: 4px;
}

:deep(.el-checkbox__label) {
  font-size: 16px;
  color: #333;
}


.w-full {
  background-color: #006DB8;
  border-color: #006DB8;
}


.copyright {
  font-size: 20px;
  font-family: Arial;
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: #333;
  text-align: center;
}

.tab-button,
.el-button,
.forgot-password,
.refresh-icon {
  transition: all .3s cubic-bezier(.4, 0, .2, 1);
}

.el-button {
  box-shadow: 0 2px 6px rgba(0, 109, 184, .18);
}

.el-button:hover {
  background-color: #0079d4;
  border-color: #0079d4;
  box-shadow: 0 4px 12px rgba(0, 109, 184, .28);
  transform: translateY(-2px) scale(1.02);
}

.el-button:active {
  transform: translateY(0) scale(.98);
  box-shadow: 0 1px 4px rgba(0, 109, 184, .18);
}

.tab-button:hover {
  color: #006DB8;
  transform: translateY(-1px) scale(1.05);
}

.tab-button.active {
  color: #006DB8;
  font-weight: 600;
}

.forgot-password:hover {
  color: #004d8a;
  transform: scale(1.05);
}

.refresh-icon:hover {
  transform: rotate(180deg) scale(1.15);
}

.el-button--primary {
  background-color: #006DB8;
  border-color: #006DB8;
}

.el-button--primary:hover,
.el-button--primary:focus {
  background-color: #006DB8;
  border-color: #006DB8;
  filter: brightness(1.08);
}

.el-button--primary:active {
  background-color: #006DB8;
  border-color: #006DB8;
  filter: brightness(0.95);
}
</style>
